import { actions } from "../../http/actions";
import { hc } from "../../hc";
import HCMqttBaseService from "../BaseService";

export default class HCMQTTParamsService extends HCMqttBaseService {

	/** 获取系统参数 */
	async getConfig(topic: string) {
		const operator = actions.Getconfig;
		const data = {
			operator,
			info: {},
		};
		const client = this.getMQTTClient();
		const res = await client.fetch<hc.mqtt.getConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置系统参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 */
	async upConfig(topic: string, config: Partial<hc.mqtt.getConfigAck["info"]>) {
		const operator = actions.Upconfig;
		const data = {
			operator,
			info: {
				...config,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upConfigAck>(topic, data);
		return res;
	}

	/** 获取声音及界面信息参数 */
	async getSoundConfig(topic: string) {
		const operator = actions.GetSoundconfig;
		const data = {
			operator,
			info: {},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getSoundConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置声音及界面参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 */
	async upSoundConfig(topic: string, params: Partial<hc.mqtt.getSoundConfigAck["info"]>) {
		const operator = actions.UpSoundconfig;
		const data = {
			operator,
			info: {
				...params,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upSoundConfigAck>(topic, data);
		return res;
	}

	/** 获取开门条件参数 */
	async getDoorConfig(topic: string) {
		const operator = actions.GetDoorconfig;
		const data = {
			operator,
			info: {},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getDoorConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置开门条件参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 *
	 */
	async upDoorConfig(topic: string, params: Partial<hc.mqtt.getDoorConfigAck["info"]>) {
		const operator = actions.UpDoorconfig;
		const data = {
			operator,
			info: { ...params },
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upDoorConfigAck>(topic, data);
		return res;
	}

	/** 获取http订阅配置参数 */
	async getHTTPConfig(topic: string) {
		const operator = actions.GetHTTPconfig;
		const data = {
			operator,
			info: {},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getHTTPConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置http订阅参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 *
	 */
	async upHTTPConfig(topic: string, params: Partial<hc.mqtt.getHTTPConfigAck["info"]>) {
		const operator = actions.UpHTTPconfig;
		const data = {
			operator,
			info: {
				...params,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upHTTPConfigAck>(topic, data);
		return res;
	}

	/** 获取温度参数，只有测温的设备才支持此配置 */
	async getTPTConfig(topic: string) {
		const operator = actions.GetTPTconfig;
		const data = { operator, info: {} };
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getTPTConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置温度参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 *
	 */
	async upTPTConfig(topic: string, params: Partial<hc.mqtt.getTPTConfigAck["info"]>) {
		const operator = actions.UpTPTconfig;
		const data = {
			operator,
			info: { ...params },
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upTPTConfigAck>(topic, data);
		return res;
	}

	/**
	 * 获取mqtt参数配置
	 */
	async getMQTTConfig(topic: string) {
		const operator = actions.GetMQTTconfig;
		const data = { operator, info: {} };
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getMQTTConfigAck>(topic, data);
		return res;
	}

	/**
	 * 设置mqtt参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 *
	 */
	async upMQTTConfig(topic: string, params: Partial<hc.mqtt.getMQTTConfigAck["info"]>) {
		const operator = actions.UpMQTTconfig;
		const data = {
			operator,
			info: {
				...params,
			},
		};
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upMQTTConfigAck>(topic, data);
		return res;
	}

	/** 获取人脸识别参数 */
	async getFaceConfig(topic: string) {
		const operator = actions.GetFaceconfig;
		const data = { operator, info: {} };
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.getFaceConfigAck>(topic, data);
		return res;
	}
	/**
	 * 设置人脸识别参数
	 *
	 * 注意参数中不必提供facesluiceId和result字段
	 *
	 */
	async upFaceConfig(topic: string, params: Partial<hc.mqtt.getFaceConfigAck["info"]>) {
		const operator = actions.UpFaceconfig;
		const data = { operator, info: { ...params } };
		const client = this.getMQTTClient();

		const res = await client.fetch<hc.mqtt.upFaceConfigAck>(topic, data);
		return res;
	}
}
